package io.jee.caisan.weixin.config;

import java.util.HashSet;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import io.jee.caisan.weixin.domain.SysMember;
import io.jee.caisan.weixin.service.SysMemberService;

@Component
public class StartupRunner implements CommandLineRunner {

	@Resource
	private SysMemberService sysMemberService;
	
    @Override
    public void run(String... args) throws Exception {
    	SysMember sysMember = sysMemberService.getSysMemberByUsername("admin");
    	if(sysMember == null) {
    		sysMember = new SysMember();
    		sysMember.setUsername("admin");
    		sysMember.setPassword("CSadmin@2017");
    		Set<String> authoritie = new HashSet<>();
    		authoritie.add("admin");
    		sysMember.setAuthorities(authoritie);
    		sysMemberService.addSysMember(sysMember);
    	}
    }

}